package app.ui.component;

import app.ui.Config;
import app.ui.MainFrame;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @Description 游戏菜单
 * @Date 2022/4/10 21:43
 * @Created by LYP
 */
public class GameMenu extends JMenu implements Config {

    MainFrame mainFrame;

    public GameMenu(MainFrame mainFrame) {
        this.mainFrame = mainFrame;
        init();
    }

    private void init() {
        setName("游戏");
        setSize(80, MENU_SIZE);
        setLayout(null);
        JMenuItem startGame = add("开始游戏");
        startGame.setSize(80, MENU_SIZE);
        startGame.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                mainFrame.isGameStart = true;
            }
        });
        JMenuItem exitGame = add("退出");
        exitGame.setSize(80, MENU_SIZE);
        exitGame.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
    }
}
